package com.Ajava1704.linkedhashmap;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @类名: com.Ajava1704.linkedhashmap
 * @作者: lgt
 * @创建时间: 2020-02-12 17:37
 * @描述:
 **/
public class LRUCache<K,V> extends LinkedHashMap<K,V> {
    private int maxEntries;

    public LRUCache(int maxEntries) {
        super(16, 0.75f, true);
        this.maxEntries = maxEntries;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > maxEntries;
    }

    public static void main(String[] args) {
        LRUCache<String,Object> cache = new LRUCache<>(3);
        cache.put("a","abstract");
        cache.put("b","basic");
        cache.put("c","call");
        cache.get("a");
        cache.put("d","滴滴滴");
        System.out.println(cache); // 输出为：{c=call, a=abstract, d=滴滴滴}
  }
}
